home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb11.zip / CHOICES.PAS < prev    next >
Pascal/Delphi Source File  |  1985-07-13  |  3KB  |  128 lines

  1. program choices;
  2.  
  3. {
  4.  This program demonstrates how choices from a menu can be made by pointing
  5.   (like Lotus' 1-2-3) instead of entering a number.
  6.  
  7. Source: "Choices: A Generalized Menu Technique", TUG Lines Volume I Issue 3
  8. Author: Barry Abrahamsen
  9. Application: All systems (some modification required)
  10. }
  11.  
  12. const
  13.   up_arrow    = #$82; {the values for the ADVANTAGE}
  14.   down_arrow  = #$8A;
  15.   norm_video  = #$02;
  16.   rev_video   = #$01;
  17.  
  18.   max_choices =    3;  {one less than the actual number of choices}
  19.   cr          = #$0d;
  20.   bell        = #$07;
  21.  
  22. type
  23.   choice_type = record         { more information could be included here}
  24.     row           : integer;   { and that information returned by GET_CHOICE,}
  25.     column        : integer;   { instead of just the position of the choice in}
  26.     description   : string[60];{ the array }
  27.   end;
  28.  
  29. var
  30.   choice : array[0..max_choices] of choice_type;
  31.   result : integer;
  32.  
  33. procedure beep;
  34. begin
  35.   write(bell);
  36. end;
  37.  
  38. procedure turn_on(choice : choice_type);  {highlights a menu choice}
  39. begin
  40.   gotoxy(choice.column, choice.row);
  41.   write(rev_video, choice.description, norm_video);
  42. end;
  43.  
  44. procedure turn_off(choice : choice_type); {cancels the highlighting}
  45. begin
  46.   gotoxy(choice.column, choice.row);
  47.   write(norm_video, choice.description, rev_video);
  48. end;
  49.  
  50. procedure initialize_choices; { puts the descriptions of the menu choices}
  51.                               { and their location on the screen in an  }
  52. var                           { array }
  53.   i :integer;
  54.  
  55. begin
  56.   for i := 0 to max_choices do
  57.     with choice[i] do
  58.       begin
  59.         row := i + 5;  {each choice on a different row}
  60.         column := 5;
  61.         description := 'This is a choice'; {all choice descriptions the same}
  62.       end;
  63.  
  64. end;
  65.  
  66. procedure display_choices;
  67.  
  68. var
  69.   i : integer;
  70.  
  71. begin
  72.   clrscr;
  73.   for i := 0 to max_choices do
  74.     with choice[i] do
  75.       begin
  76.         gotoxy(column, row);
  77.         write(description);
  78.       end;
  79.    turn_on(choice[0]);
  80.  
  81. end; {display_choices}
  82.  
  83.  
  84. function get_choice : integer;
  85.  
  86. var
  87.   c : char;
  88.   current, last : integer;
  89.  
  90. begin
  91.   current := 0;
  92.   last := 0;
  93.   repeat                {loop until they hit the RETURN key}
  94.     read(kbd, c);
  95.     case c of
  96.        up_arrow, ^X   : begin                {^X and ^E usage reversed from }
  97.                           last := current;   { WordStar }
  98.                           current := last + 1;
  99.                         end;
  100.  
  101.        down_arrow, ^E : begin
  102.                           last := current;
  103.                           if last <> 0 then
  104.                             current := last - 1
  105.                           else
  106.                             current := max_choices;
  107.                         end;
  108.  
  109.        else             if c <> cr then beep;
  110.     end; {case}
  111.     if c in [up_arrow, down_arrow, ^E, ^X] then
  112.       begin
  113.         current := current mod (max_choices + 1);
  114.         turn_off(choice[last]);
  115.         turn_on(choice[current]);
  116.       end;
  117.   until c = cr; {end repeat}
  118.   get_choice := current;
  119. end; {get_choice}
  120.  
  121. begin
  122.   initialize_choices;
  123.   display_choices;
  124.   result := get_choice;
  125.   gotoxy(20,20);
  126.   write(result:1, ' was your choice.');
  127. end.
  128.